package com.song.druid.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.time.LocalDateTime;
import java.io.Serializable;

import com.song.druid.annotation.AutoId;
import com.song.druid.annotation.ParamRegex;
import com.song.druid.annotation.SensitiveData;
import com.song.druid.annotation.SensitiveField;
import com.song.druid.api.Insert;
import com.song.druid.api.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Null;

/**
 * <p>
 * 用户信息
 * </p>
 *
 * @author song
 * @since 2023-11-09
 */
@SensitiveData
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("user_info")
@ApiModel(value="UserInfo对象", description="用户信息")
public class UserInfo extends Model<UserInfo> {

    private static final long serialVersionUID = 1L;

    @AutoId(AutoId.IdType.SNOWFLAKE)
    @Null(message = "新增数据不能有id", groups = Insert.class)
    @NotBlank(message = "缺少用户id", groups = Update.class)
    @ApiModelProperty(value = "用户id")
    @TableId(value = "id")
    private String id;

    @ApiModelProperty(value = "姓名")
    @TableField("name")
    private String name;

    @ParamRegex(pattern = "[abcds][0-9]*")
    @ApiModelProperty(value = "证件号码")
    @TableField("id_card")
    private String idCard;

    @Length(min = 6, max = 20, message = "请检查账号长度是否在6-20区间")
    @ApiModelProperty(value = "账号")
    @TableField("username")
    private String username;

    @SensitiveField
    @ApiModelProperty(value = "密码")
    @TableField("password")
    private String password;

    @ApiModelProperty(value = "用户状态（禁用-0 正常-1）")
    @TableField("status")
    private String status;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "update_Time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
